package com.zqq.demo.fragment

import android.widget.TextView
import androidx.databinding.ViewDataBinding
import com.zqq.base.BaseFragment
import com.zqq.base.BaseShareFragment
import com.zqq.base.utils.LogUtils
import com.zqq.demo.R
import com.zqq.demo.databinding.FragmentBBinding
import com.zqq.demo.viewmodel.MainViewModel
import org.json.JSONObject

class BFragment: BaseShareFragment<MainViewModel, FragmentBBinding>() {
    override fun setContentViewId(): Int = R.layout.fragment_b

    override fun init() {
        viewModel.list.observe(this){
           changeShow()
        }

        viewModel.selectIndex.observe(this){
            changeShow()
        }
    }

    private fun changeShow() {
        viewModel.list.value?.get(viewModel.selectIndex.value?:0)?.let {
            JSONObject(it).let {
                viewBinding.main.removeAllViews()
                val textView = TextView(activity)
                textView.setText("分享者：${it.optString("shareUser")}")
                viewBinding.main.addView(textView)

                val textView1 = TextView(activity)
                textView1.setText("地址：${it.optString("link")}")
                viewBinding.main.addView(textView1)
            }
        }
    }
}